package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import pojo.Menu;
import util.ConexaoPPCP;

public class MenuDao {
	private ArrayList<Menu> menu = new ArrayList<Menu>();

	public ArrayList<Menu> localizarMenu(int id) throws SQLException, ClassNotFoundException{
		Connection conexao = ConexaoPPCP.getConexaoPPCP();
		String sql = "select distinct m.id, m.label, m.descricao from menu m, menuitem i, categoriamenuitem c where m.id=i.menu_id and c.menuitem_id =i.id and c.categoriausuario_id = ?";
		PreparedStatement pst = conexao.prepareStatement(sql);
		pst.setInt(1, id);
		ResultSet rs = pst.executeQuery();
		while(rs.next()){
			Menu meuMenu = new Menu();
			meuMenu.setLabel(rs.getString("label"));
			meuMenu.setDescricao(rs.getString("descricao"));
			MenuItemDao meuItemMenuDao = new MenuItemDao();
			meuMenu.setMenuitem(meuItemMenuDao.localizarMenuItem(id, rs.getInt("id")));
			menu.add(meuMenu);
		}
                return menu;
	}
}
